﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Diagnostics;

namespace AzureDriveUI
{
	public static class DriveMenuManager
	{
		static DriveMenuManager()
		{
			_menu = new MenuItem
			{
				Header = "Drives",
			};
		}

		static MenuItem _menu;

		public static MenuItem GetMenu(ContextMenu parentMenu)
		{
			parentMenu.Opened += Opened;

			return _menu;
		}

		static void Opened(object sender, System.Windows.RoutedEventArgs e)
		{
			_menu.Items.Clear();

			foreach (var item in DriveConfigurationManager.GetConfiguredDrives())
			{
				string driveLetter = item.DriveLetter + @":\";
				string display = string.Format("{0} - {1}", driveLetter, item.VolumeLabel);

				var driveMenuItem = new MenuItem
				{
					Header = display,
				};

				driveMenuItem.Click += delegate
				{
					try
					{
						Process.Start(driveLetter);
					}
					catch { }
				};

				_menu.Items.Add(driveMenuItem);
			}
		}
	}
}
